package com.heima.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @Author 96558
 * @Date 2021/1/14 11:38
 * @Version 1.0
 **/
public class OssDemo {
    public static void main(String[] args) {
        // Endpoint以杭州为例，其它Region请按实际情况填写。
        String endpoint = "oss-cn-shanghai.aliyuncs.com";
        // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。
        String accessKeyId = "LTAI4GDBRfvQHkfVKjRRTCKK";
        String accessKeySecret = "ttZfR6rci1CVE6prBpGZ867cgX6GPn";

        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        // 上传Byte数组。
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream("D://1.jpg");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        PutObjectResult result = ossClient.putObject("itcast-zwq", "itheima/itcast.jpg", inputStream);

        // 关闭OSSClient。
        ossClient.shutdown();
    }
}
